import ModuleBase from "./Module/ModuleBase";
import ModuleMgr from "./Module/ModuleMgr";
import PlayerLayer from "./Module/PlayerLayer";


const { ccclass, property } = cc._decorator;

@ccclass
export default class Game extends cc.Component {

    protected onLoad(): void {
        this._registerModule();
        ModuleMgr.instance.onInitModule();
        let playerLayer = ModuleMgr.instance.getModule<PlayerLayer>("PlayerLayer");
        playerLayer.createPlayer();
    }

    start() {
        ModuleMgr.instance.onLateInitModule();
    }

    update(deltaTime: number) {
        ModuleMgr.instance.onUpdateModule(deltaTime);
    }
    protected lateUpdate(dt: number): void {
        ModuleMgr.instance.onLateUpdateModule(dt);
    }

    //将Game下面的所有模块都存入模块管理中
    private _registerModule() {
        //这里的孩子节点应该是直接孩子节点，不包括孙子节点
        for (let child of this.node.children) {
            //只有继承与ModuleBse的模块才会被存入
            let module: ModuleBase = child.getComponent(ModuleBase);
            if (module) {
                ModuleMgr.instance.addModule(child.name, module);
            }
        }
    }
}


